"""
@File    :   data_operate.py
@Time    :   2024/03/19 16:07:40
@Author  :   Qrj
@Email   :   923207736@qq.com
@description   :   数据初始化等操作
"""

from datetime import datetime

from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
from sqlalchemy.orm import sessionmaker

from src.business.admin.system.menu.enums import MenuTypeEnum
from src.business.admin.system.menu.schemas.validate import MenuCreateValidateSchema
from src.business.admin.system.menu.service import MenuService
from src.business.admin.system.tenant.tenant.schemas.validate import (
    TenantCreateValidateSchema,
)
from src.business.admin.system.tenant.tenant.service import TenantService
from src.config import get_app_settings

# 获取应用配置
settings = get_app_settings()

# 创建异步引擎对象
async_engine = create_async_engine(
    settings.master_async_orm_url,
    echo=settings.orm_echo,
    future=settings.orm_future,
    pool_size=settings.orm_process_pool_size,
    pool_pre_ping=settings.orm_pool_pre_ping,
)
# 创建异步会话管理对象(连接池对象, 每次调用就会取出一个连接)
masterSessionLocal = sessionmaker(
    async_engine,
    class_=AsyncSession,
    autocommit=settings.orm_auto_commit,
    autoflush=settings.orm_auto_flush,
    expire_on_commit=settings.orm_expire_on_commit,
)
# 创建连接
session: AsyncSession = masterSessionLocal()


class DataInitOperate:
    """cli的数据初始化相关操作类"""

    @staticmethod
    async def create_system_tenant_and_user_and_oauth2_client():
        """
        1. 创建初始系统租户
        2. 创建租户的管理员用户
        3. 创建租户的oauth2客户端信息(password模式和swagger模式)
        """
        # 创建所需参数
        create_schema = TenantCreateValidateSchema(
            name="系统租户",
            remark="初始化时创建的系统级别租户",
            expiration_datetime=datetime.now(),
            quota=999999998,
            tenant_package_id=1,
            admin_username=settings.default_system_tenant_admin_username,
            admin_password=settings.default_system_tenant_admin_password,
            admin_name=settings.default_system_tenant_admin_name,
            admin_remark="初始系统租户的管理员用户",
        )
        # 创建初始系统级别租户(会同时创建该租户对应的管理员用户、初始Oauth2客户端)
        await TenantService.create_tenant(session, create_schema, is_system=True)

    @staticmethod
    async def create_menu():
        """创建初始菜单"""
        # 创建初始菜单
        # 系统管理(目录)
        create_system_schema = MenuCreateValidateSchema(
            name="系统管理",
            path="/system",
            icon="svg-icon:system",
            parent_id=0,
            type=MenuTypeEnum.directory.value,
            show_order=1,
        )
        create_system_id = await MenuService.create_menu(
            session, create_system_schema, is_system=True
        )
        # 租户管理(目录)
        create_tenant_schema = MenuCreateValidateSchema(
            name="租户管理",
            path="tenant",
            icon="ep:office-building",
            parent_id=create_system_id,
            type=MenuTypeEnum.directory.value,
            show_order=1,
        )
        create_tenant_id = await MenuService.create_menu(
            session, create_tenant_schema, is_system=True
        )
        # 租户管理(菜单)
        create_tenant_tenant_schema = MenuCreateValidateSchema(
            name="租户管理",
            path="tenant",
            icon="svg-icon:tenant",
            parent_id=create_tenant_id,
            show_order=1,
            type=MenuTypeEnum.menu.value,
            component="system/tenant/index",
            component_name="SystemTenant",
        )
        create_tenant_tenant_id = await MenuService.create_menu(
            session, create_tenant_tenant_schema, is_system=True
        )
        # 租户查询(按鈕)
        create_tenant_tenant_select_schema = MenuCreateValidateSchema(
            name="租户查询",
            parent_id=create_tenant_tenant_id,
            show_order=1,
            type=MenuTypeEnum.button.value,
            permission="admin@system@tenant@tenant:select",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_tenant_tenant_select_schema, is_system=True
        )
        # 租户创建(按钮)
        create_tenant_tenant_create_schema = MenuCreateValidateSchema(
            name="租户创建",
            parent_id=create_tenant_tenant_id,
            show_order=2,
            type=MenuTypeEnum.button.value,
            permission="admin@system@tenant@tenant:create",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_tenant_tenant_create_schema, is_system=True
        )
        # 租户修改(按钮)
        create_tenant_tenant_update_schema = MenuCreateValidateSchema(
            name="租户修改",
            parent_id=create_tenant_tenant_id,
            show_order=3,
            type=MenuTypeEnum.button.value,
            permission="admin@system@tenant@tenant:update",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_tenant_tenant_update_schema, is_system=True
        )
        # 租户删除(按钮)
        create_tenant_tenant_delete_schema = MenuCreateValidateSchema(
            name="租户删除",
            parent_id=create_tenant_tenant_id,
            show_order=4,
            type=MenuTypeEnum.button.value,
            permission="admin@system@tenant@tenant:delete",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_tenant_tenant_delete_schema, is_system=True
        )
        # 租户套餐管理
        create_tenant_package_schema = MenuCreateValidateSchema(
            name="租户套餐管理",
            path="package",
            icon="svg-icon:tenant_package",
            parent_id=create_tenant_id,
            show_order=2,
            type=MenuTypeEnum.menu.value,
            component="system/tenantPackage/index",
            component_name="SystemTenantPackage",
        )
        create_tenant_package_id = await MenuService.create_menu(
            session, create_tenant_package_schema, is_system=True
        )
        # 租户套餐查询(按鈕)
        create_tenant_package_select_schema = MenuCreateValidateSchema(
            name="租户套餐查询",
            parent_id=create_tenant_package_id,
            show_order=1,
            type=MenuTypeEnum.button.value,
            permission="admin@system@tenant@package:select",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_tenant_package_select_schema, is_system=True
        )
        # 租户套餐创建(按钮)
        create_tenant_package_create_schema = MenuCreateValidateSchema(
            name="租户套餐创建",
            parent_id=create_tenant_package_id,
            show_order=2,
            type=MenuTypeEnum.button.value,
            permission="admin@system@tenant@package:create",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_tenant_package_create_schema, is_system=True
        )
        # 租户套餐修改(按钮)
        create_tenant_package_update_schema = MenuCreateValidateSchema(
            name="租户套餐修改",
            parent_id=create_tenant_package_id,
            show_order=3,
            type=MenuTypeEnum.button.value,
            permission="admin@system@tenant@tenant:update",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_tenant_package_update_schema, is_system=True
        )
        # 租户套餐删除(按钮)
        create_tenant_package_delete_schema = MenuCreateValidateSchema(
            name="租户套餐删除",
            parent_id=create_tenant_package_id,
            show_order=4,
            type=MenuTypeEnum.button.value,
            permission="admin@system@tenant@package:delete",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_tenant_package_delete_schema, is_system=True
        )
        # 用户管理
        create_user_schema = MenuCreateValidateSchema(
            name="用户管理",
            path="user",
            icon="ep:avatar",
            parent_id=create_system_id,
            show_order=3,
            type=MenuTypeEnum.menu.value,
            component="system/user/index",
            component_name="SystemUser",
        )
        create_user_id = await MenuService.create_menu(
            session, create_user_schema, is_system=True
        )
        # 用户查询(按鈕)
        create_user_select_schema = MenuCreateValidateSchema(
            name="用户查询",
            parent_id=create_user_id,
            show_order=1,
            type=MenuTypeEnum.button.value,
            permission="admin@system@user:select",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_user_select_schema, is_system=True
        )
        # 用户创建(按钮)
        create_user_create_schema = MenuCreateValidateSchema(
            name="用户创建",
            parent_id=create_user_id,
            show_order=2,
            type=MenuTypeEnum.button.value,
            permission="admin@system@user:create",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_user_create_schema, is_system=True
        )
        # 用户修改(按钮)
        create_user_update_schema = MenuCreateValidateSchema(
            name="用户修改",
            parent_id=create_user_id,
            show_order=3,
            type=MenuTypeEnum.button.value,
            permission="admin@system@user:update",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_user_update_schema, is_system=True
        )
        # 用户删除(按钮)
        create_user_delete_schema = MenuCreateValidateSchema(
            name="用户删除",
            parent_id=create_user_id,
            show_order=4,
            type=MenuTypeEnum.button.value,
            permission="admin@system@user:delete",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_user_delete_schema, is_system=True
        )
        # 重置用户密码(按钮)
        create_reset_user_password_schema = MenuCreateValidateSchema(
            name="重置用户密码",
            parent_id=create_user_id,
            show_order=5,
            type=MenuTypeEnum.button.value,
            permission="admin@system@user:reset_user_password",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_reset_user_password_schema, is_system=True
        )
        # 分配用户角色(按钮)
        create_assign_user_role_schema = MenuCreateValidateSchema(
            name="分配用户角色",
            parent_id=create_user_id,
            show_order=6,
            type=MenuTypeEnum.button.value,
            permission="admin@system@user:assign_user_role",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_assign_user_role_schema, is_system=True
        )
        # 角色管理
        create_role_schema = MenuCreateValidateSchema(
            name="角色管理",
            path="role",
            icon="svg-icon:role",
            parent_id=create_system_id,
            show_order=4,
            type=MenuTypeEnum.menu.value,
            component="system/role/index",
            component_name="SystemRole",
        )
        create_role_id = await MenuService.create_menu(
            session, create_role_schema, is_system=True
        )
        # 角色查询(按鈕)
        create_role_select_schema = MenuCreateValidateSchema(
            name="角色查询",
            parent_id=create_role_id,
            show_order=1,
            type=MenuTypeEnum.button.value,
            permission="admin@system@role:select",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_role_select_schema, is_system=True
        )
        # 角色创建(按钮)
        create_role_create_schema = MenuCreateValidateSchema(
            name="角色创建",
            parent_id=create_role_id,
            show_order=2,
            type=MenuTypeEnum.button.value,
            permission="admin@system@role:create",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_role_create_schema, is_system=True
        )
        # 角色修改(按钮)
        create_role_update_schema = MenuCreateValidateSchema(
            name="角色修改",
            parent_id=create_role_id,
            show_order=3,
            type=MenuTypeEnum.button.value,
            permission="admin@system@role:update",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_role_update_schema, is_system=True
        )
        # 角色删除(按钮)
        create_role_delete_schema = MenuCreateValidateSchema(
            name="角色删除",
            parent_id=create_role_id,
            show_order=4,
            type=MenuTypeEnum.button.value,
            permission="admin@system@role:delete",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_role_delete_schema, is_system=True
        )
        # 分配角色菜单权限(按钮)
        create_assign_role_menu_schema = MenuCreateValidateSchema(
            name="分配角色菜单权限",
            parent_id=create_role_id,
            show_order=5,
            type=MenuTypeEnum.button.value,
            permission="admin@system@role:assign_role_menu",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_assign_role_menu_schema, is_system=True
        )
        # 菜单管理(菜单)
        create_menu_schema = MenuCreateValidateSchema(
            name="菜单管理",
            path="menu",
            icon="svg-icon:menu",
            parent_id=create_system_id,
            show_order=2,
            type=MenuTypeEnum.menu.value,
            component="system/menu/index",
            component_name="SystemMenu",
        )
        create_menu_id = await MenuService.create_menu(
            session, create_menu_schema, is_system=True
        )
        # 菜单查询(按鈕)
        create_menu_select_schema = MenuCreateValidateSchema(
            name="菜单查询",
            parent_id=create_menu_id,
            show_order=1,
            type=MenuTypeEnum.button.value,
            permission="admin@system@menu:select",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_menu_select_schema, is_system=True
        )
        # 菜单创建(按钮)
        create_menu_create_schema = MenuCreateValidateSchema(
            name="菜单创建",
            parent_id=create_menu_id,
            show_order=2,
            type=MenuTypeEnum.button.value,
            permission="admin@system@menu:create",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_menu_create_schema, is_system=True
        )
        # 菜单修改(按钮)
        create_menu_update_schema = MenuCreateValidateSchema(
            name="菜单修改",
            parent_id=create_menu_id,
            show_order=3,
            type=MenuTypeEnum.button.value,
            permission="admin@system@menu:update",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_menu_update_schema, is_system=True
        )
        # 菜单删除(按钮)
        create_menu_delete_schema = MenuCreateValidateSchema(
            name="菜单删除",
            parent_id=create_menu_id,
            show_order=4,
            type=MenuTypeEnum.button.value,
            permission="admin@system@menu:delete",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_menu_delete_schema, is_system=True
        )
        # 字典管理(菜单)
        create_create_dict_schema = MenuCreateValidateSchema(
            name="字典管理",
            path="dict",
            icon="svg-icon:dict",
            parent_id=create_system_id,
            show_order=5,
            type=MenuTypeEnum.menu.value,
            component="system/dict/index",
            component_name="SystemDict",
        )
        create_dict_id = await MenuService.create_menu(
            session, create_create_dict_schema, is_system=True
        )
        # 字典类型查询(按鈕)
        create_dict_type_select_schema = MenuCreateValidateSchema(
            name="字典类型查询",
            parent_id=create_dict_id,
            show_order=1,
            type=MenuTypeEnum.button.value,
            permission="admin@system@dict@type:select",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_dict_type_select_schema, is_system=True
        )
        # 字典类型创建(按钮)
        create_dict_type_create_schema = MenuCreateValidateSchema(
            name="字典类型创建",
            parent_id=create_dict_id,
            show_order=2,
            type=MenuTypeEnum.button.value,
            permission="admin@system@dict@type:create",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_dict_type_create_schema, is_system=True
        )
        # 字典类型修改(按钮)
        create_dict_type_update_schema = MenuCreateValidateSchema(
            name="字典类型修改",
            parent_id=create_dict_id,
            show_order=3,
            type=MenuTypeEnum.button.value,
            permission="admin@system@dict@type:update",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_dict_type_update_schema, is_system=True
        )
        # 字典类型删除(按钮)
        create_dict_type_delete_schema = MenuCreateValidateSchema(
            name="字典类型删除",
            parent_id=create_dict_id,
            show_order=4,
            type=MenuTypeEnum.button.value,
            permission="admin@system@dict@type:delete",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_dict_type_delete_schema, is_system=True
        )
        # 字典数据查询(按鈕)
        create_dict_data_select_schema = MenuCreateValidateSchema(
            name="字典数据查询",
            parent_id=create_dict_id,
            show_order=5,
            type=MenuTypeEnum.button.value,
            permission="admin@system@dict@data:select",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_dict_data_select_schema, is_system=True
        )
        # 字典数据创建(按钮)
        create_dict_data_create_schema = MenuCreateValidateSchema(
            name="字典数据创建",
            parent_id=create_dict_id,
            show_order=6,
            type=MenuTypeEnum.button.value,
            permission="admin@system@dict@data:create",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_dict_data_create_schema, is_system=True
        )
        # 字典数据修改(按钮)
        create_dict_data_update_schema = MenuCreateValidateSchema(
            name="字典数据修改",
            parent_id=create_dict_id,
            show_order=7,
            type=MenuTypeEnum.button.value,
            permission="admin@system@dict@data:update",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_dict_data_update_schema, is_system=True
        )
        # 字典数据删除(按钮)
        create_dict_data_delete_schema = MenuCreateValidateSchema(
            name="字典数据删除",
            parent_id=create_dict_id,
            show_order=8,
            type=MenuTypeEnum.button.value,
            permission="admin@system@dict@data:delete",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_dict_data_delete_schema, is_system=True
        )
        # Oauth2管理(目录)
        create_oauth2_schema = MenuCreateValidateSchema(
            name="Oauth2管理",
            path="oauth2",
            icon="svg-icon:oauth2",
            parent_id=create_system_id,
            type=MenuTypeEnum.directory.value,
            show_order=6,
        )
        create_oauth2_id = await MenuService.create_menu(
            session, create_oauth2_schema, is_system=True
        )
        # oauth2客户端管理(菜单)
        create_oauth2_client_schema = MenuCreateValidateSchema(
            name="客户端管理",
            path="client",
            icon="svg-icon:client",
            parent_id=create_oauth2_id,
            show_order=1,
            type=MenuTypeEnum.menu.value,
            component="system/oauth2/client/index",
            component_name="SystemOauth2Client",
        )
        create_oauth2_client_id = await MenuService.create_menu(
            session, create_oauth2_client_schema, is_system=True
        )
        # oauth2客户端查询(按鈕)
        create_oauth2_client_select_schema = MenuCreateValidateSchema(
            name="客户端查询",
            parent_id=create_oauth2_client_id,
            show_order=1,
            type=MenuTypeEnum.button.value,
            permission="admin@system@oauth2@client:select",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_oauth2_client_select_schema, is_system=True
        )
        # oauth2客户端创建(按鈕)
        create_oauth2_client_create_schema = MenuCreateValidateSchema(
            name="客户端创建",
            parent_id=create_oauth2_client_id,
            show_order=2,
            type=MenuTypeEnum.button.value,
            permission="admin@system@oauth2@client:create",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_oauth2_client_create_schema, is_system=True
        )
        # oauth2客户端修改(按鈕)
        create_oauth2_client_update_schema = MenuCreateValidateSchema(
            name="客户端修改",
            parent_id=create_oauth2_client_id,
            show_order=3,
            type=MenuTypeEnum.button.value,
            permission="admin@system@oauth2@client:update",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_oauth2_client_update_schema, is_system=True
        )
        # oauth2客户端删除(按鈕)
        create_oauth2_client_delete_schema = MenuCreateValidateSchema(
            name="客户端删除",
            parent_id=create_oauth2_client_id,
            show_order=4,
            type=MenuTypeEnum.button.value,
            permission="admin@system@oauth2@client:delete",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_oauth2_client_delete_schema, is_system=True
        )
        # Oauth2的Token管理(菜单)
        create_oauth2_token_schema = MenuCreateValidateSchema(
            name="Token管理",
            path="token",
            icon="svg-icon:token",
            parent_id=create_oauth2_id,
            show_order=2,
            type=MenuTypeEnum.menu.value,
            component="system/oauth2/token/index",
            component_name="SystemOauth2Token",
        )
        create_oauth2_token_id = await MenuService.create_menu(
            session, create_oauth2_token_schema, is_system=True
        )
        # Oauth2的Token查询(按鈕)
        create_oauth2_token_select_schema = MenuCreateValidateSchema(
            name="Token查询",
            parent_id=create_oauth2_token_id,
            show_order=1,
            type=MenuTypeEnum.button.value,
            permission="admin@system@oauth2@token:select",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_oauth2_token_select_schema, is_system=True
        )
        # Oauth2的Token强退(按鈕)
        create_oauth2_token_force_logout_schema = MenuCreateValidateSchema(
            name="Token强退",
            parent_id=create_oauth2_token_id,
            show_order=2,
            type=MenuTypeEnum.button.value,
            permission="admin@system@oauth2@token:force_logout",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_oauth2_token_force_logout_schema, is_system=True
        )
        # 通知公告管理(菜单)
        create_notice_schema = MenuCreateValidateSchema(
            name="通知公告管理",
            path="notice",
            icon="svg-icon:notice",
            parent_id=create_system_id,
            show_order=7,
            type=MenuTypeEnum.menu.value,
            component="system/notice/index",
            component_name="SystemNotice",
        )
        create_notice_id = await MenuService.create_menu(
            session, create_notice_schema, is_system=True
        )
        # 通知公告查询(按鈕)
        create_notice_select_schema = MenuCreateValidateSchema(
            name="通知公告查询",
            parent_id=create_notice_id,
            show_order=1,
            type=MenuTypeEnum.button.value,
            permission="admin@system@notice:select",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_notice_select_schema, is_system=True
        )
        # 通知公告创建(按鈕)
        create_notice_create_schema = MenuCreateValidateSchema(
            name="通知公告创建",
            parent_id=create_notice_id,
            show_order=2,
            type=MenuTypeEnum.button.value,
            permission="admin@system@notice:create",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_notice_create_schema, is_system=True
        )
        # 通知公告修改(按鈕)
        create_notice_update_schema = MenuCreateValidateSchema(
            name="通知公告修改",
            parent_id=create_notice_id,
            show_order=3,
            type=MenuTypeEnum.button.value,
            permission="admin@system@notice:update",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_notice_update_schema, is_system=True
        )
        # 通知公告删除(按鈕)
        create_notice_delete_schema = MenuCreateValidateSchema(
            name="通知公告删除",
            parent_id=create_notice_id,
            show_order=4,
            type=MenuTypeEnum.button.value,
            permission="admin@system@notice:delete",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_notice_delete_schema, is_system=True
        )
        # 站内信管理(目录)
        create_station_message_schema = MenuCreateValidateSchema(
            name="站内信管理",
            path="station-message",
            icon="svg-icon:station_message",
            parent_id=create_system_id,
            type=MenuTypeEnum.directory.value,
            show_order=8,
        )
        create_station_message_id = await MenuService.create_menu(
            session, create_station_message_schema, is_system=True
        )
        # 站内信模板管理(菜单)
        create_station_message_template_schema = MenuCreateValidateSchema(
            name="模板管理",
            path="template",
            icon="svg-icon:template",
            parent_id=create_station_message_id,
            show_order=1,
            type=MenuTypeEnum.menu.value,
            component="system/stationMessageTemplate/index",
            component_name="SystemStationMessageTemplate",
        )
        create_station_message_template_id = await MenuService.create_menu(
            session, create_station_message_template_schema, is_system=True
        )
        # 站内信模板查询(按鈕)
        create_station_message_template_select_schema = MenuCreateValidateSchema(
            name="模板查询",
            parent_id=create_station_message_template_id,
            show_order=1,
            type=MenuTypeEnum.button.value,
            permission="admin@system@station_message@template:select",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_station_message_template_select_schema, is_system=True
        )
        # 站内信模板创建(按鈕)
        create_station_message_template_create_schema = MenuCreateValidateSchema(
            name="模板创建",
            parent_id=create_station_message_template_id,
            show_order=2,
            type=MenuTypeEnum.button.value,
            permission="admin@system@station_message@template:create",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_station_message_template_create_schema, is_system=True
        )
        # 站内信模板修改(按鈕)
        create_station_message_template_update_schema = MenuCreateValidateSchema(
            name="模板修改",
            parent_id=create_station_message_template_id,
            show_order=3,
            type=MenuTypeEnum.button.value,
            permission="admin@system@station_message@template:update",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_station_message_template_update_schema, is_system=True
        )
        # 站内信模板删除(按鈕)
        create_station_message_template_delete_schema = MenuCreateValidateSchema(
            name="模板删除",
            parent_id=create_station_message_template_id,
            show_order=4,
            type=MenuTypeEnum.button.value,
            permission="admin@system@station_message@template:delete",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_station_message_template_delete_schema, is_system=True
        )
        # 发送站内信测试消息(按鈕)
        create_send_test_station_message_schema = MenuCreateValidateSchema(
            name="发送站内信测试消息",
            parent_id=create_station_message_template_id,
            show_order=5,
            type=MenuTypeEnum.button.value,
            permission="admin@system@station_message@template:send_test_station_message",
            visible=False,
            keep_alive=False,
        )
        await MenuService.create_menu(
            session, create_send_test_station_message_schema, is_system=True
        )
        # 站内信消息记录(菜单)
        create_station_message_record_schema = MenuCreateValidateSchema(
            name="消息记录",
            path="record",
            icon="svg-icon:record",
            parent_id=create_station_message_id,
            show_order=2,
            type=MenuTypeEnum.menu.value,
            component="system/stationMessageRecord/index",
            component_name="SystemStationMessageRecord",
        )
        create_station_message_record_id = await MenuService.create_menu(
            session, create_station_message_record_schema, is_system=True
        )

    @staticmethod
    async def create_dict():
        """创建字典"""
        pass

    @staticmethod
    async def data_init():
        # 创建系统租户、管理员、oauth2客户端
        await DataInitOperate.create_system_tenant_and_user_and_oauth2_client()
        # 创建菜单
        await DataInitOperate.create_menu()
